package com.vc.aha_server_event.service;

import com.github.pagehelper.PageHelper;
import com.vc.aha_server_event.entity.Event;
import com.vc.aha_server_event.entity.EventRecord;
import com.vc.aha_server_event.mapper.EventMapper;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Properties;

@Service
public class EventService {
    @Resource
    private EventMapper eventMapper;
    @Resource
    private MongoTemplate mongoTemplate;

    public Event getEvent(int eventId) {
        return eventMapper.selectByPrimaryKey(eventId);
    }

    public int deleteEvent(int eventId) {
        return eventMapper.deleteByPrimaryKey(eventId);
    }

    public int insertEvent(Event event) {
        eventMapper.insertSelective(event);
        return event.getEventId();
    }

    public int updateEvent(Event event) {
        return eventMapper.updateByPrimaryKeySelective(event);
    }

    public List<Event> getAllEvent(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("eventId desc");
        List<Event> eventList= eventMapper.selectAll();
        return eventList;
    }

    public void insertEventRecord(EventRecord eventRecord){
        mongoTemplate.save(eventRecord);
    }
}
